<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="wt.httpgw.URLFactory"%>
<%@page import="wt.doc.WTDocument"%>
<%@page import="wt.fc.ReferenceFactory"%>
<%@page import="shmged.com.shlcm.utils.CmCreateDocHelper" %>
<%@page import="java.util.*" %>
<%
	String baseUrl = new URLFactory().getBaseHREF();
	ReferenceFactory rc=new ReferenceFactory();
	String oid=request.getParameter("oid");
	String type=request.getParameter("type");
	WTDocument doc=(WTDocument)rc.getReference(oid).getObject();
	String priName="无";
	if(CmCreateDocHelper.getPrimaryFile(doc).size()>0){
		Map priMap=(Map)CmCreateDocHelper.getPrimaryFile(doc).get(0);
		priName=(String)priMap.get("name");
	}
	List secondaryList=CmCreateDocHelper.getSecondaryFile(doc);

%>
<head>
<title>修改文档</title>
</head>
<body>


<center>
<div style="margin:10px 0;"></div>
	<div class="easyui-panel" title="修改文档" style="width:900px" >
		<div style="padding:10px 0 10px 60px">
<form method="post" enctype="multipart/form-data" name="updateForm" id="updateForm" >
<input type="hidden" value="<%=oid %>" id="oid" name="oid"></input>
<input type="hidden" value="false" id="priId" name="priId"></input>
<input type="hidden" value="" id="secId" name="secId"></input>
  <table>
  	  <tr id="oldPri">
  	  	<td>主内容</td>
  	  	<td><div id="delPrimary"><%=priName %> &nbsp;&nbsp;&nbsp;&nbsp;<a href="javaScript:void(0)" onclick="deletePrimary()">更改</a> </div></td>
  	  </tr>
  	  <tr id="newPri" style="display:none">
      <td>主要内容</td>
      <td>
        <input  type="file" id="inp_updatePrimary" name="inp_updatePrimary"  size="65" onchange="setUpdateName()"/>
      </td>
    </tr>
    <tr>
      <td style="width:100px">*名称</td>
      <td>
        <input class="easyui-validatebox" data-options="required:true" value="<%=doc.getName() %>" name="updateName" id="updateName" type="text" size="65" />
      </td>
    </tr>
    <tr>
      <td >说明</td>
      <td>
        <textarea name="updateDesc" id="updateDesc" cols="65" rows="5" value="<%=doc.getDescription() %>"></textarea>
      </td>
    </tr>
    <tr>
    	<td>附件：</td>
    	<td>
    	
    	<% for(int i=0;i<secondaryList.size();i++){
				Map map=(Map)secondaryList.get(i);
			%>
			<div id="sec<%=map.get("name") %>"><%=map.get("name") %>&nbsp; &nbsp;&nbsp;<a href="javaScript:void(0)"   onclick="delSec('<%=map.get("name") %>')">删除</a>	<br/></div>
			<%} %>
    	</td>
    </tr>
    
    <tr>
      <td colspan="2">
            <br/>
          附件：<a href="javascript:void(0)" onclick="addAppendix2('appendixFileId2')">添加附件</a>
               </td>
    </tr>
     <tr>
                <td colspan="2">
                <div id="appendixFileId2"></div>
                </td>
				
            </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="center"><label>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitUpdateForm()">提交</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearUpdateForm()">关闭</a>
      </label></td>
    </tr>
  </table>
</form>
</div>
</div>
</center>
<script type="text/javascript">

	function deletePrimary()
	{
		document.getElementById("oldPri").style.display="none";
		document.getElementById("newPri").style.display="";
		document.getElementById("priId").value="true";		
	}

	function delSec(docName)
	{
		var secVal=document.getElementById("secId").value;
		document.getElementById("secId").value=secVal+docName+"__";	
		var iid="sec"+docName;
		document.getElementById(iid).style.display="none";	
	}
	function setUpdateName()
	{
		var value=document.getElementById("inp_updatePrimary").value;
		value=value.substring(value.lastIndexOf("\\")+1,value.lastIndexOf(".")); 
		document.getElementById("updateName").value=value;
	}
	function submitUpdateForm(){
	 var docName=document.getElementById("updateName").value;
	 if(docName==""||docName==null)
	 {
		 alert("名称不能为空");
		 return;
	}
		
	$('#updateForm').submit()
	}
	function clearUpdateForm(){
		$('#cmTabs').tabs('close','修改文档');
	}
	/*添加附件功能*/
	function addAppendix2(htmlId){
		//alert("appendixFileId :"+htmlId);
		var $div = $("#"+htmlId);
		var len = $div.children("input[type='file']") + 1;
		//alert("len :"+len);
		$div.append("<div><input type='file' size=60 name='appendixFile_"+len+"' /><input type='button' value='-' onclick='removeAppendix2(this)'></input></div>");
	}
	function removeAppendix2(obj){
		var temp = $(obj);
		temp.parent("div").remove(); 
	}
	
	function initUpdateDoc(){
		var docName="文档:<%=doc.getName()%>";
		$("#updateForm").form({
			url:'<%=baseUrl%>shmged/jsp/com/shlcm/documents/jspUpdateDocument.jsp',
			onSubmit:function (){
			},
			success:function (data){
				//alert(data);
				if(data.indexOf("ERROR") != -1){
					$.messager.alert('提示',data);
				}else{
					var oid=data.split("__");
					$.messager.alert('提示',oid[0]);
					$('#cmTabs').tabs('close','修改文档');
				//	initDocTable("/Default");
					
					if("<%=type%>"=="browse")
					{
						initDocTable("/Default");
					}else
					{
						initDocsTable();
					}				
				}
				
				hideProcessMsg("prince_process_ques");
			},
			onLoadError:function (){
				hideProcessMsg("prince_process_ques");
			}
		});
	}

	//创建一个新的tab 文档信息
	function refedocInfo(tabObj,tabId,oid,docName){
		var defaultTabId = "cmTabs";
		if(tabId){
			defaultTabId = tabId;
		}
		var tabDefault = {
			href:pageBaseUrl+"shmged/jsp/com/shlcm/documents/docInfo.jsp?oid="+oid,
			title:"文档:"+docName,
			selected: true,
			closable:true
		};
		var options ;
		if(tabObj){
		    var empty = {};
			options = $.extend(empty,tabDefault,tabObj);
		}else{
			options = tabDefault;
		}
		if($('#'+defaultTabId).tabs("exists",options.title)){
			$('#'+defaultTabId).tabs('select',options.title);
		}else{
		    $('#'+defaultTabId).tabs('add',options);
		}
//		alert(tab.outerHeight()+":"+tab.innerHeight());
//	    alert("index:"+index);
		//var oldHeight = p.panel('panel').outerHeight();  
		//setHeight();
	}
	initUpdateDoc();
</script>
</body>

</html>


